﻿using PoliticalClassifier.Domain;
using PoliticalClassifier.Support;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace PoliticalClassifier.Application.TestBench
{
    class Program
    {
        static void Main(string[] args)
        {
            Random rand = new Random();

            String fileName = @"..\..\..\PoliticalClassifier.DataSource.Tests\TestFiles\Social_Economic_DataMicro.xlsx";

            PoliticalClassifierModeler modeler = new PoliticalClassifierModeler();
            modeler.FileName = fileName;
            modeler.Load();

            foreach (string columnName in modeler.ColumnNames)
            {
                if (columnName != Constants.COLUMN_NAME_ID)
                {
                    Point2D dataPoint = new Point2D(
                        2.0 * (rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble()) / 6.0 - 1.0,
                        2.0 * (rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble() + rand.NextDouble()) / 6.0 - 1.0);
                    modeler.WeightManager.AddWeight(new WeightAttribute(columnName, dataPoint));
                }
            }

            Candidate candidate1 = new Candidate();
            candidate1.Name = "Candidate 1";
            candidate1.Color = Color.Red;
            candidate1.Location = new Point2D(0.2, 0.5);
            modeler.CandidateManager.AddCandidate(candidate1);

            Candidate candidate2 = new Candidate();
            candidate2.Name = "Candidate 2";
            candidate2.Color = Color.Blue;
            candidate2.Location = new Point2D(0.0, 0.0);
            modeler.CandidateManager.AddCandidate(candidate2);

            ISimulationResults simulationResults = modeler.Compute();

            MessageBox.Show("Overall Median Point:" + simulationResults.OverallVoterMedianPoint, "Message");
            foreach(ICandidateResults results in simulationResults.CandidateResults.SortedDescendingByNumberOfVotes())
            {
                MessageBox.Show(results.Candidate.Name + 
                    "\nNumber of Votes: " + results.NumberOfVotes + 
                    "\nDistance From Median: " + results.DistanceFromMedian, 
                    "Message");
            }

            modeler.PlotGraph(simulationResults).Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TestPlot.png"));
        }
    }
}
